import {Login} from "../api/user";

export default new Vuex.Store({
    state:{
        username: '',
        permission:''
    },
    mutations: {
        setUserName(state, username, permission) {
            state.username = username;
            state.permission = permission
        },
    },
    actions: {
        async login({commit},parms) {
            const resp = await Login(parms);
            console.log(resp)
            if (resp.status === 200){
                commit('setUserName', username,resp.permission);
                localStorage.setItem('token',resp.token)
            }else {
                return Promise.reject(resp)
            }
        }

    }
})
